// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 下载 —————————————————————————————— //

  async remoteDownload({ state: { API, downParam, MAP } }) {
    const msg = await API.download(downParam, MAP.tipDown)
    return msg
  },

  // —————————————————————————————— 上传 —————————————————————————————— //

  async remoteUpload({ state: { API, upParam, upProgress, MAP } }) {
    const bytes = await CORE.fileBytes(upParam.file)
    upParam.taskId = await API.upload({ content: bytes }, MAP.tipUp)
    upProgress.file = upParam.file
  },

  // —————————————————————————————— 上传进度 —————————————————————————————— //

  async remoteUpProgress({ state: { API, upParam, upProgress, MAP } }) {
    const resp = await API.upProgress(upParam)
    if (resp.progress < upProgress.percent) return // 忽略异常进度

    return {
      finish: resp.isFinish,
      tip: resp.describe,
      num: resp.finishRow,
      total: resp.totalRow,
      percent: resp.progress,
      success: resp.isSuccess,
    }
  },
}
